/**
 * 
 */
package com.googlecode.gwtresume.client.widgets;

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.ComplexPanel;
import com.google.gwt.user.client.ui.Widget;

public class UnorderedList extends ComplexPanel {

	String delimiter = null;
	
	public UnorderedList() {
		setElement(DOM.createElement("ul"));
	}

	public UnorderedList(String style) {
		this();
		setStylePrimaryName(style);
	}
	
	public void setDelimiter(String delimiter) {
		this.delimiter = delimiter;
	}

	public void add(Widget w) {
		if (getWidgetCount() > 0 && delimiter != null) {
			ListItem li = (ListItem) getWidget(getWidgetCount() - 1);
			li.setText(li.getText() + delimiter);
		}
		super.add(wrap(w), getElement());
	}

	public void insert(Widget w, int beforeIndex) {
		super.insert(wrap(w), getElement(), beforeIndex, true);
	}
	
	Widget wrap(Widget child) {
		if (child instanceof UnorderedList) {
			ListItem wrapper = new ListItem();
			wrapper.add(child);
			return wrapper;
		} else return child;
		
	}

}